package com.ecube.maintenance.utils;

import com.google.gson.Gson;

import java.lang.reflect.Type;

/**
 * Created by Trible Chen on 2014/9/6.
 */
public class GsonUtil {

    public static String toString(Object o,Type type){
        Gson g = new Gson();
        return g.toJson(o,type);
    }
    public static <T> T getInfoFromJson(byte[] arg2,Type t){
        try {
            String content = StringUtil.getStringForByte(arg2);
            Bog.v(content);
            T result = new Gson().fromJson(content,t );
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }
    public static <T> T getInfosFromJson(byte[] arg2 , Type t){
        String content = StringUtil.getStringForByte(arg2);
        return getInfosFromJson(content, t);
    }
    public static <T> T getInfosFromJson(String arg2 , Type t){
        try {
            String content = arg2;
            Bog.v(content);
            T tmp = new Gson().fromJson(content,t);
            return tmp;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

    }
}
